package practice1_100;

import java.util.Deque;
import java.util.LinkedList;

public class Practice877 {
    public static boolean stoneGame(int[] piles) {
        Deque<Integer> list=new LinkedList<>();
        for(int i=0;i<piles.length;i++){
            list.add(piles[i]);
        }
        int alx=0,lee=0;
        while(!list.isEmpty()){
            if(list.peekFirst()>list.peekLast()){
                alx+=list.pollFirst();
            }else alx+=list.pollLast();
            if(list.peekFirst()>list.peekLast()){
                lee+=list.pollFirst();
            }else lee+=list.pollLast();
        }
        return alx>lee?true:false;
    }

    public static void main(String[] args) {
        boolean a=stoneGame(new int[]{5,3,4,5});

    }
}
